package com.ophiux.FeverManagement.aplication.serviceImpl.doctor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.FeverManagement.aplication.bean.doLoginDoctorRequest;
import com.ophiux.FeverManagement.aplication.bean.doLoginDoctorResonse;
import com.ophiux.FeverManagement.aplication.service.doctor.doLoginDoctorService;
import com.ophiux.FeverManagement.domain.entity.DoctorInfo;
import com.ophiux.FeverManagement.domain.repository.IDoctorRepositories;
import com.ophiux.micro.core.application.Result;
import com.ophiux.micro.core.application.ResultEnum;
import com.ophiux.utils.common.ShiftUtils;
@Service("doLoginDoctorService")
public class doLoginDoctorServiceimpl implements doLoginDoctorService{
	@Autowired
	IDoctorRepositories doctorRepositories;//医生信息仓储
	
	@Override
	public Result<doLoginDoctorResonse> doLoginDoctor(doLoginDoctorRequest dto) {
		Result<doLoginDoctorResonse> result = new Result<>();
		if(!dto.isParamValid()) {
			return Result.fail(ResultEnum.requestParamFail);
		}
		try {
			String otherId = dto.getOTHER_ID();
			DoctorInfo doctorInfo = doctorRepositories.getDoctorByOtherId(otherId);
			if(doctorInfo == null) {//未找到医生用户信息  登录失败
				return Result.fail(ResultEnum.NotFundUser);
			}
			doLoginDoctorResonse response = (doLoginDoctorResonse) ShiftUtils.objToNewObj(doctorInfo, doLoginDoctorResonse.class);
			response.setDOCTOR_ID(doctorInfo.getUSER_ID());
			
			result = Result.success(response);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.fail("","操作异常");
		}
		return result;
	}

}
